/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SMbuSource;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.*;

/**
 *
 * @author danielg_ramos
 */
public class Sender {
    public void send(String dest, String text){
        try {
    // Construct data
    String data = URLEncoder.encode("usuario", "UTF-8") + "=" + URLEncoder.encode("6ps", "UTF-8");
    data += "&" + URLEncoder.encode("senha", "UTF-8") + "=" + URLEncoder.encode("polvo321", "UTF-8");
    data += "&" + URLEncoder.encode("dest", "UTF-8") + "=" + URLEncoder.encode(dest, "UTF-8");
    data += "&" + URLEncoder.encode("texto", "UTF-8") + "=" + URLEncoder.encode(text, "UTF-8");

    // Send data
    URL url = new URL("http://www.iagentesms.com.br/gateway/sms.php");
    
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(data);
    wr.flush();

    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
        System.out.println("Retorno: " + line);
    }
    wr.close();
    rd.close();
} catch (Exception e) {
}

    }

}
